package com.future.bantang.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import com.future.bantang.R;

public class RecommendShareActivity extends AppCompatActivity {

    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recommend_share);

        Intent intent = getIntent();
        String shareUrl = intent.getStringExtra("shareUrl");
        Toast.makeText(this, shareUrl, Toast.LENGTH_SHORT).show();

        webView = (WebView) findViewById(R.id.wv_recommend_share);

        webView.setWebViewClient(new WebViewClient() {
            //在原有webview上加载数据
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl(shareUrl);
        //webview监听是否可以后退
        webView.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (webView.canGoBack()) {
                    webView.goBack();
                } else {
                    finish();
                }
                return false;
            }
        });
    }
}
